import {ipcRenderer} from 'electron'


export const postsAPI = {
    // 获取笔记目录树
    getPostsTree(navName){
        return ipcRenderer.invoke('get:posts:tree', navName)
    },
    // 生成vitepress配置文件
    generateVitepressConfig(){
        return ipcRenderer.invoke('generate:vitepress:config')
    },

    // 写入新笔记
    writeNewNote(noteId, content=''){
        return ipcRenderer.invoke('write:new:note', noteId, content)
    },
    // 删除笔记
    deleteNode(nodeId){
        return ipcRenderer.invoke('delete:node', nodeId)
    },
    // 保存笔记
    saveNote(noteId, content){
        return ipcRenderer.invoke('save:note', noteId, content)
    },

    getMoveDir(currendID){
        return ipcRenderer.invoke('get:move:dir', currendID)
    },
    moveFile(currendID, targetID){
        return ipcRenderer.invoke('move:file', currendID, targetID)
    },
    moveDir(currendID, targetID){
        return ipcRenderer.invoke('move:dir', currendID, targetID)
    },
    // 启动服务
    startService(port){
        return ipcRenderer.invoke('start:service', port)
    },
    // 停止服务
    stopService(){
        return ipcRenderer.invoke('stop:service')
    },
    // 服务日志监听
    onStdoutLog: (callback) => ipcRenderer.on('service:stdout:log', callback),
    onStderrLog: (callback) => ipcRenderer.on('service:stderr:log', callback),
    onServiceClose: (callback) => ipcRenderer.on('service:close:log', callback),

}